﻿using FtpUploadWeb.Common;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace FtpUploadWeb
{
    public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            //读取配置文件
            var host = Configuration["host"];
            //执行异地备份的定时作业
            FtpHelper.host = host;
            FtpHelper.user = Configuration["user"];
            FtpHelper.password = Configuration["password"];
            FtpHelper.port = Convert.ToInt32(Configuration["port"]);
            FtpHelper.upLoadFileDirectory = Configuration["upLoadFileDirectory"].TrimEnd('\\');
            FtpHelper.ftpSaveDirectory = Configuration["ftpSaveDirectory"];
            TaskManage.TimingBackupTask = Configuration["TimingBackupTask"];

            //执行Bat文件的定时作业
            BatHelper.BatFilePath = Configuration["BatFilePath"];
            TaskManage.TimingBatTask = Configuration["TimingBatTask"];

            services.AddLogging();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" }
                );
            });
        }
    }
}
